﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExpenseTracker.Entity
{
    public class QueryYear
    {
        List<QueryMonth> _months = new List<QueryMonth>();

        public QueryYear(int year)
        {
            Year = year;
        }

        public int Year { get; set; }

        public List<QueryMonth> Months
        {
            get
            {
                if (_months.Count == 0)
                {
                    _months.Add(new QueryMonth("January", GetFirstDayOfMonth(Year, 1), GetLastDayOfMonth(Year, 1)));
                    _months.Add(new QueryMonth("February", GetFirstDayOfMonth(Year, 2), GetLastDayOfMonth(Year, 2)));
                    _months.Add(new QueryMonth("March", GetFirstDayOfMonth(Year, 3), GetLastDayOfMonth(Year, 3)));
                    _months.Add(new QueryMonth("April", GetFirstDayOfMonth(Year, 4), GetLastDayOfMonth(Year, 4)));
                    _months.Add(new QueryMonth("May", GetFirstDayOfMonth(Year, 5), GetLastDayOfMonth(Year, 5)));
                    _months.Add(new QueryMonth("June", GetFirstDayOfMonth(Year, 6), GetLastDayOfMonth(Year, 6)));
                    _months.Add(new QueryMonth("July", GetFirstDayOfMonth(Year, 7), GetLastDayOfMonth(Year, 7)));
                    _months.Add(new QueryMonth("August", GetFirstDayOfMonth(Year, 8), GetLastDayOfMonth(Year, 8)));
                    _months.Add(new QueryMonth("September", GetFirstDayOfMonth(Year, 9), GetLastDayOfMonth(Year, 9)));
                    _months.Add(new QueryMonth("October", GetFirstDayOfMonth(Year, 10), GetLastDayOfMonth(Year, 10)));
                    _months.Add(new QueryMonth("November", GetFirstDayOfMonth(Year, 11), GetLastDayOfMonth(Year, 11)));
                    _months.Add(new QueryMonth("December", GetFirstDayOfMonth(Year, 12), GetLastDayOfMonth(Year, 12)));
                }

                return _months;
            }
        }

        private DateTime GetFirstDayOfMonth(int year, int month)
        {
            DateTime dt = new DateTime(year, month, 1);
            return dt;
        }

        private DateTime GetLastDayOfMonth(int year, int month)
        {
            DateTime dt = new DateTime(year, month, 1);
            dt = dt.AddMonths(1);
            dt = dt.AddDays(-(dt.Day));
            return dt;
        }
    }
}
